package xyz.scootaloo.oj.leetcode

import org.junit.Test

/**
 * @author flutterdash@qq.com
 * @since 2021/4/8 10:09
 */
class P307 {

    /**
     * [1, 3, 5] [1, 2, 5]
     * <1, 4, 9> <1, 3, 8>
     */
    inner class NumArray(private val nums: IntArray) {

        fun update(index: Int, `val`: Int) {
            nums[index] = `val`
        }

        fun sumRange(left: Int, right: Int): Int {
            var sum = 0
            for (idx in left..right) {
                sum += nums[idx]
            }
            return sum
        }

    }

    @Test
    fun test0() {
        val input = intArrayOf(1, 3, 5)
        val numArray = NumArray(input)
        println(numArray.sumRange(0, 2))
        println(numArray.update(1, 2))
        println(numArray.sumRange(0, 2))
    }

}
